package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.FieldExpand;
import com.ruoyi.system.service.IFieldExpandService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 字段拓展Controller
 * 
 * @author ruoyi
 * @date 2024-02-26
 */
@RestController
@RequestMapping("/system/expand")
public class FieldExpandController extends BaseController
{
    @Autowired
    private IFieldExpandService fieldExpandService;

    /**
     * 查询字段拓展列表
     */
    @PreAuthorize("@ss.hasPermi('system:expand:list')")
    @GetMapping("/list")
    public TableDataInfo list(FieldExpand fieldExpand)
    {
        startPage();
        List<FieldExpand> list = fieldExpandService.selectFieldExpandList(fieldExpand);
        return getDataTable(list);
    }

    /**
     * 导出字段拓展列表
     */
    @PreAuthorize("@ss.hasPermi('system:expand:export')")
    @Log(title = "字段拓展", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FieldExpand fieldExpand)
    {
        List<FieldExpand> list = fieldExpandService.selectFieldExpandList(fieldExpand);
        ExcelUtil<FieldExpand> util = new ExcelUtil<FieldExpand>(FieldExpand.class);
        util.exportExcel(response, list, "字段拓展数据");
    }

    /**
     * 获取字段拓展详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:expand:query')")
    @GetMapping(value = "/{expandId}")
    public AjaxResult getInfo(@PathVariable("expandId") Long expandId)
    {
        return success(fieldExpandService.selectFieldExpandByExpandId(expandId));
    }

    /**
     * 新增字段拓展
     */
    @PreAuthorize("@ss.hasPermi('system:expand:add')")
    @Log(title = "字段拓展", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FieldExpand fieldExpand)
    {
        return toAjax(fieldExpandService.insertFieldExpand(fieldExpand));
    }

    /**
     * 修改字段拓展
     */
    @PreAuthorize("@ss.hasPermi('system:expand:edit')")
    @Log(title = "字段拓展", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FieldExpand fieldExpand)
    {
        return toAjax(fieldExpandService.updateFieldExpand(fieldExpand));
    }

    /**
     * 删除字段拓展
     */
    @PreAuthorize("@ss.hasPermi('system:expand:remove')")
    @Log(title = "字段拓展", businessType = BusinessType.DELETE)
	@DeleteMapping("/{expandIds}")
    public AjaxResult remove(@PathVariable Long[] expandIds)
    {
        return toAjax(fieldExpandService.deleteFieldExpandByExpandIds(expandIds));
    }
}
